#include <iostream>
#include <string>

using namespace std;

/*
浅拷贝: 如果类的内部没有指针  并不需要创建动态 内存空间
深拷贝: 如果类的内部有指针  需要创建动态内存空间
*/

class my_class;

class my_class
{
private:
public:
    int *ptr;
    int val;

    my_class();
    my_class(const my_class & cl);
    ~my_class();
};

int main(int argc, char const *argv[])
{
    my_class cl;
    *cl.ptr = 100;
    cl.val = 200;

    my_class cl2 = cl;

    cout << cl.ptr << " " << *cl.ptr << " " << cl.val << endl;
    cout << cl2.ptr << " " << *cl2.ptr << " " << cl2.val << endl;
    
    return 0;
}

my_class::my_class()
{
    ptr = new int(10);
    cout << "调用了构造" << endl;
}

my_class::my_class(const my_class &cl) // 拷贝构造
{
    ptr = new int(*cl.ptr);
    val = cl.val;
}

my_class::~my_class()
{
    if (ptr != NULL)
    {
        delete ptr;
        ptr = NULL;
        cout << "调用了析构" << endl;
        return;
    }
    cout << "重复调用" << endl;
}
